GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#2843)
by Brendan
04:11
created

$.fn.symphonyDefaultValue   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 71

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 71
rs 9.1369
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/**
2
 * @package assets
3
 */
4
5
(function($, Symphony) {
0 ignored issues
show
Unused Code introduced by
The parameter Symphony is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
6
7
	/**
8
	 * Fills the target input/textarea with a value from the source element.
9
	 * The plugin cease to change the value when the target is edited by the user and has a value.
10
	 *
11
	 * @name $.symphonyDefaultValue
12
	 * @class
13
	 *
14
	 * @param {Object} options An object specifying containing the attributes specified below
15
	 * @param {String} [options.sourceElement='.js-defaultvalue-source'] Selector to find the default value
16
	 * @param {String} [options.sourceEvent='select'] The event that triggers setting the value in the target element
17
	 * @param {String} [options.targetEvent='keyup blur'] The event(s) to watch for user interaction
18
	 *
19
	 * @example
20
21
			$('.js-defaultvalue-target').symphonyDefaultValue();
22
	 */
23
	$.fn.symphonyDefaultValue = function(options) {
24
		var objects = this,
25
			isOn = false,
26
			settings = {
27
				sourceElement: '.js-defaultvalue-source',
28
				sourceEvent: 'change',
29
				targetEvent: 'keyup blur'
30
			};
31
32
		$.extend(settings, options);
33
34
		// append our namespace on the sourceEvent
35
		settings.sourceEvent += '.symphony-defaultvalue';
36
37
		var source = $(settings.sourceElement);
38
39
		var getTargetValue = function () {
40
			return objects.val();
41
		};
42
43
		var setTargetValue = function (val) {
44
			objects.val(val);
45
		};
46
47
		var getSourceValue = function () {
48
			return source.find('option:selected').text();
49
		};
50
51
		var sourceChanged = function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
52
			if (isOn) {
53
				setTargetValue(getSourceValue());
54
			}
55
		};
56
57
		var on = function () {
58
			if (isOn) {
59
				return;
60
			}
61
			source.on(settings.sourceEvent, sourceChanged);
62
			isOn = true;
63
		};
64
65
		var off = function () {
66
			if (!isOn) {
67
				return;
68
			}
69
			$(settings.sourceElement).off(settings.sourceEvent);
70
			isOn = false;
71
		};
72
73
	/*-------------------------------------------------------------------------
74
		Initialisation
75
	-------------------------------------------------------------------------*/
76
77
		objects.on(settings.targetEvent, function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
78
			if (!getTargetValue()) {
79
				on();
80
			}
81
			else {
82
				off();
83
			}
84
		});
85
86
		if (!getTargetValue()) {
87
			on();
88
		}
89
90
	/*-----------------------------------------------------------------------*/
91
92
		return objects;
93
	};
94
95
})(window.jQuery, window.Symphony);
96